package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.core.example.BaseExample.E_CREATE_USER_ID;
import static org.jsola.core.example.BaseExample.E_MODIFIED_USER_ID;
import static org.jsola.core.example.BaseExample.N_CREATE_USER_ID;
import static org.jsola.core.example.BaseExample.N_MODIFIED_USER_ID;
import static org.jsola.hr.example.EmpSocChangesExample.E_CENSUS_TYPE;
import static org.jsola.hr.example.EmpSocChangesExample.E_COMPANY_ID;
import static org.jsola.hr.example.EmpSocChangesExample.E_EFFECTIVE_DATE_END;
import static org.jsola.hr.example.EmpSocChangesExample.E_EFFECTIVE_DATE_START;
import static org.jsola.hr.example.EmpSocChangesExample.E_EFFECTIVE_STATUS;
import static org.jsola.hr.example.EmpSocChangesExample.E_EMP_ID;
import static org.jsola.hr.example.EmpSocChangesExample.E_GMT_CREATE_END;
import static org.jsola.hr.example.EmpSocChangesExample.E_GMT_CREATE_START;
import static org.jsola.hr.example.EmpSocChangesExample.E_GMT_MODIFIED_END;
import static org.jsola.hr.example.EmpSocChangesExample.E_GMT_MODIFIED_START;
import static org.jsola.hr.example.EmpSocChangesExample.E_PERSON_TAX_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.E_PERSON_TAX_PROP;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_AMOUNT_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_AMOUNT_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_BASIC;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_CITY;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_PAYBACK_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_PAYBACK_MONTH_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_PAYBACK_MONTH_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_PROP_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_PROP_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_TAX_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.E_PF_UNPAY_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_AMOUNT_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_AMOUNT_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_BASIC;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_CITY;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_MAIN;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_PAYBACK_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_PAYBACK_MONTH_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_PAYBACK_MONTH_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_PROP_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_PROP_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_TYPE;
import static org.jsola.hr.example.EmpSocChangesExample.E_SOC_UNPAY_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.E_WORK_INJURY_PROP;
import static org.jsola.hr.example.EmpSocChangesExample.N_CENSUS_TYPE;
import static org.jsola.hr.example.EmpSocChangesExample.N_COMPANY_ID;
import static org.jsola.hr.example.EmpSocChangesExample.N_EFFECTIVE_DATE_END;
import static org.jsola.hr.example.EmpSocChangesExample.N_EFFECTIVE_DATE_START;
import static org.jsola.hr.example.EmpSocChangesExample.N_EFFECTIVE_STATUS;
import static org.jsola.hr.example.EmpSocChangesExample.N_EMP_ID;
import static org.jsola.hr.example.EmpSocChangesExample.N_GMT_CREATE_END;
import static org.jsola.hr.example.EmpSocChangesExample.N_GMT_CREATE_START;
import static org.jsola.hr.example.EmpSocChangesExample.N_GMT_MODIFIED_END;
import static org.jsola.hr.example.EmpSocChangesExample.N_GMT_MODIFIED_START;
import static org.jsola.hr.example.EmpSocChangesExample.N_PERSON_TAX_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.N_PERSON_TAX_PROP;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_AMOUNT_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_AMOUNT_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_BASIC;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_CITY;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_PAYBACK_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_PAYBACK_MONTH_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_PAYBACK_MONTH_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_PROP_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_PROP_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_TAX_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.N_PF_UNPAY_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_AMOUNT_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_AMOUNT_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_BASIC;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_CITY;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_MAIN;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_PAYBACK_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_PAYBACK_MONTH_AMOUNT;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_PAYBACK_MONTH_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_PROP_COMPANY;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_PROP_PERSON;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_REMARK;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_TYPE;
import static org.jsola.hr.example.EmpSocChangesExample.N_SOC_UNPAY_MONTH;
import static org.jsola.hr.example.EmpSocChangesExample.N_WORK_INJURY_PROP;

/**
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class EmpSocChangesQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_EMP_ID, example = E_EMP_ID)
    @Length(max = 32)
    private String empId;

    @ApiParam(value = N_SOC_CITY, example = E_SOC_CITY)
    @Length(max = 32)
    private String socCity;

    @ApiParam(value = N_SOC_TYPE, example = E_SOC_TYPE)
    private Boolean socType;

    @ApiParam(value = N_SOC_BASIC, example = E_SOC_BASIC)
    private Integer socBasic;

    @ApiParam(value = N_SOC_PROP_COMPANY, example = E_SOC_PROP_COMPANY)
    private BigDecimal socPropCompany;

    @ApiParam(value = N_SOC_PROP_PERSON, example = E_SOC_PROP_PERSON)
    private BigDecimal socPropPerson;

    @ApiParam(value = N_SOC_AMOUNT_COMPANY, example = E_SOC_AMOUNT_COMPANY)
    private Integer socAmountCompany;

    @ApiParam(value = N_SOC_AMOUNT_PERSON, example = E_SOC_AMOUNT_PERSON)
    private Integer socAmountPerson;

    @ApiParam(value = N_SOC_REMARK, example = E_SOC_REMARK)
    @Length(max = 255)
    private String socRemark;

    @ApiParam(value = N_SOC_MAIN, example = E_SOC_MAIN)
    private Integer socMain;

    @ApiParam(value = N_CENSUS_TYPE, example = E_CENSUS_TYPE)
    private Integer censusType;

    @ApiParam(value = N_WORK_INJURY_PROP, example = E_WORK_INJURY_PROP)
    private BigDecimal workInjuryProp;

    @ApiParam(value = N_PF_CITY, example = E_PF_CITY)
    @Length(max = 32)
    private String pfCity;

    @ApiParam(value = N_PF_BASIC, example = E_PF_BASIC)
    private Integer pfBasic;

    @ApiParam(value = N_PF_PROP_COMPANY, example = E_PF_PROP_COMPANY)
    private BigDecimal pfPropCompany;

    @ApiParam(value = N_PF_PROP_PERSON, example = E_PF_PROP_PERSON)
    private BigDecimal pfPropPerson;

    @ApiParam(value = N_PF_AMOUNT_COMPANY, example = E_PF_AMOUNT_COMPANY)
    private Integer pfAmountCompany;

    @ApiParam(value = N_PF_AMOUNT_PERSON, example = E_PF_AMOUNT_PERSON)
    private Integer pfAmountPerson;

    @ApiParam(value = N_PF_TAX_AMOUNT, example = E_PF_TAX_AMOUNT)
    private Integer pfTaxAmount;

    @ApiParam(value = N_PF_REMARK, example = E_PF_REMARK)
    @Length(max = 255)
    private String pfRemark;

    @ApiParam(value = N_PERSON_TAX_PROP, example = E_PERSON_TAX_PROP)
    private BigDecimal personTaxProp;

    @ApiParam(value = N_PERSON_TAX_AMOUNT, example = E_PERSON_TAX_AMOUNT)
    private Integer personTaxAmount;

    @ApiParam(value = N_SOC_UNPAY_MONTH, example = E_SOC_UNPAY_MONTH)
    private Boolean socUnpayMonth;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_PF_UNPAY_MONTH, example = E_PF_UNPAY_MONTH)
    private Boolean pfUnpayMonth;

    @ApiParam(value = N_SOC_PAYBACK_MONTH, example = E_SOC_PAYBACK_MONTH)
    private Boolean socPaybackMonth;

    @ApiParam(value = N_PF_PAYBACK_MONTH, example = E_PF_PAYBACK_MONTH)
    private Boolean pfPaybackMonth;

    @ApiParam(value = N_SOC_PAYBACK_MONTH_AMOUNT, example = E_SOC_PAYBACK_MONTH_AMOUNT)
    private Integer socPaybackMonthAmount;

    @ApiParam(value = N_PF_PAYBACK_MONTH_AMOUNT, example = E_PF_PAYBACK_MONTH_AMOUNT)
    private Integer pfPaybackMonthAmount;

    @ApiParam(value = N_SOC_PAYBACK_MONTH_REMARK, example = E_SOC_PAYBACK_MONTH_REMARK)
    @Length(max = 255)
    private String socPaybackMonthRemark;

    @ApiParam(value = N_PF_PAYBACK_MONTH_REMARK, example = E_PF_PAYBACK_MONTH_REMARK)
    @Length(max = 255)
    private String pfPaybackMonthRemark;

    @ApiParam(value = N_EFFECTIVE_STATUS, example = E_EFFECTIVE_STATUS)
    private Boolean effectiveStatus;

    /**
     * 生效时间查询范围
     */
    @ApiParam(value = N_EFFECTIVE_DATE_START, example = E_EFFECTIVE_DATE_START)
    private Date effectiveDateStart;
    @ApiParam(value = N_EFFECTIVE_DATE_END, example = E_EFFECTIVE_DATE_END)
    private Date effectiveDateEnd;


    /**
     * 创建时间查询范围
     */
    @ApiParam(value = N_GMT_CREATE_START, example = E_GMT_CREATE_START)
    private Date gmtCreateStart;
    @ApiParam(value = N_GMT_CREATE_END, example = E_GMT_CREATE_END)
    private Date gmtCreateEnd;


    @ApiParam(value = N_CREATE_USER_ID, example = E_CREATE_USER_ID)
    @Length(max = 32)
    private String createUserId;

    /**
     * 修改时间查询范围
     */
    @ApiParam(value = N_GMT_MODIFIED_START, example = E_GMT_MODIFIED_START)
    private Date gmtModifiedStart;
    @ApiParam(value = N_GMT_MODIFIED_END, example = E_GMT_MODIFIED_END)
    private Date gmtModifiedEnd;


    @ApiParam(value = N_MODIFIED_USER_ID, example = E_MODIFIED_USER_ID)
    @Length(max = 32)
    private String modifiedUserId;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public EmpSocChangesQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

